package com.neuedu.boot.config;

import com.neuedu.boot.interceptor.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * 项目：      springboot
 * 类名:       AppConfig
 * 创建时间：  2024/3/27 15：38
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {


    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/*");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("/index.html"); //相当于  forward
        registry.addViewController("/home").setViewName("/home.html"); //相当于  forward
        registry.addViewController("/shouye").setViewName("/home.html"); //相当于  forward
        // registry.addRedirectViewController()
    }


    /**
     * 映射静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //请求   http://localhost:8080/imgs/1.jpg      -->  /imgs/1.jpg
        // registry.addResourceHandler("/img/**").addResourceLocations("classpath:/imgs/");

        //请求   http://localhost:8080/imgs/1.jpg      -->  /imgs/imgs/1.jpg
        // registry.addResourceHandler("/**").addResourceLocations("classpath:/imgs/");
    }
}
